home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.11 Nov 87 / C string library / PStrLib Source / ShowVars.c < prev   
Encoding:
C/C++ Source or Header  |  1987-10-21  |  1.6 KB  |  60 lines  |  [TEXT/KAHL]

  1. /*    FILE:    ShowVars.c 
  2.     Displays up to 10 sets of variable labels and values.  */
  3. #include    "PStrLib.h"
  4.  
  5. ShowVars(count, varLabel, varType, varPtr)    
  6. int        count;        /* # of {varLabel,varType,varPtr} sets */
  7. char    *varLabel;    /* string label for variable */
  8. int        varType;    /* type of variable*/
  9. char    *varPtr;    /* pointer to variable */
  10. {
  11.     auto    char        **lh = &varLabel;    /* Ptr to 1st varLabel */
  12.     auto    int            *tp = &varType;        /* Ptr to 1st varType */
  13.     auto    char        **vh = &varPtr;        /* Ptr to 1st varPtr */
  14.     auto    char        *sp;
  15.     auto    Str255        s;
  16.     auto    Rect        wRect;
  17.     auto    WindowPtr    wp, savedPort;
  18.     auto    int            y = 5;
  19.     
  20.     if (count > 0) {
  21.         if (count > 10)
  22.             count = 10;    /* max number of arg. sets */
  23.         GetPort(&savedPort);
  24.         wRect.top = 45;
  25.         wRect.left = 72;
  26.         wRect.bottom = count * 20 + wRect.top + 45;
  27.         wRect.right = 440;
  28.         wp = NewWindow(NIL, &wRect, NIL, TRUE, dBoxProc, -1L, FALSE, NIL);
  29.         SetPort(wp);
  30.         while (--count >= 0) {
  31.             if (*tp == PSTR)
  32.                 sp = *vh;
  33.             else if (*tp == BOOL)
  34.                 sp = **(Boolean **)vh ? "\pTRUE" : "\pFALSE";
  35.             else {
  36.                 sp = (char *)s;
  37.                 Num2PStr(*tp, *vh, sp, DEC, (*tp >= CINT ? 0 : 6));
  38.             }
  39.             MoveTo(30, y += 20);
  40.             if (*lh && **lh)    {         /* Length of varLabel > 0? */
  41.                 DrawString(*lh);
  42.                 DrawString("\p = ");
  43.             }
  44.             DrawString(sp);
  45.             /*  
  46.                 Incr. Ptr's 10 bytes each pass so they'll
  47.                 point to the next set of arg.s on the stack.
  48.             */
  49.  
  50.             lh = (char **)((char *)lh + 10);
  51.             tp += 5;
  52.             vh = (char **)((char *)vh + 10);
  53.         }
  54.         MoveTo(30, wRect.bottom - wRect.top - 10);
  55.         DrawString("\pClick Mouse Button to Continue...");
  56.         while (!Button());    /* Wait for a mouse down event */
  57.         DisposeWindow(wp);
  58.         SetPort(savedPort);
  59.     }
  60. }